package com.jinbei.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.gkoudai.crude.service.AccountHessianService;
import com.gkoudai.pushmessage.net.PushRPCService;
import com.jinbei.bean.KvbMsgBean;
import com.jinbei.common.util.ExcelUtil;
import com.jinbei.service.KvbSendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zflu
 * Created by lucky on 2018/10/9.
 */
@Service
public class KvbSendMsgServiceImpl implements KvbSendMsgService {

    private final static String KVB_BEAN = "com.jinbei.bean.KvbMsgBean";

    @Autowired
    private AccountHessianService accountHessianService;

    @Reference(url="{dubbo.registry.address}")
    private PushRPCService pushRPCService;

    /**
     * @author zflu
     * @Description   解析excel发送kvb用户短信
     * @date 2018/10/9 14:12
     * @param file
     * @return java.lang.Boolean
     */
    @Override
    public Boolean sendMsgToKvb(MultipartFile file) throws Exception{
        boolean flag = false;
        List<String> list = null;
        if(file == null){
            return flag;
        }
        //解析excel
        ExcelUtil<KvbMsgBean> excelBeanExcelUtil = new ExcelUtil<>(KVB_BEAN);
        List<KvbMsgBean> kvbInfo = excelBeanExcelUtil.getExcelInfo(file);
        if(kvbInfo != null && kvbInfo.size() > 0){
            list = kvbInfo.stream()
                    .map(info->String.valueOf(info.getAccount()))
                    .collect(Collectors.toList());
        }
        //调用kvb hessian获取phone
        if(list != null){
            List<String> phones = accountHessianService.queryUserPhoneByUid(list);
            if(phones != null && phones.size() > 0){
                //调用dubbo发送短信
                flag = true;
            }
        }
        return flag;
    }
}
